package com.mcxx.modules.minimumliving.service.impl;

import com.mcxx.modules.minimumliving.service.MiniRescueQueryExportService;
import com.mcxx.modules.base.utils.QueryParamUtil;
import com.mcxx.modules.filemanage.easypoi.util.ExportExcelService;
import com.mcxx.modules.filemanage.file.service.FileService;
import com.mcxx.modules.miniSalvation.family.dto.MiniFamilyChangeExcelDTO;
import com.mcxx.modules.miniSalvation.family.dto.MiniMemberExcDto;
import com.mcxx.modules.miniSalvation.family.dto.MiniMemberExcelDto;
import com.mcxx.modules.miniSalvation.family.dto.MiniMemberExcelNewDto;
import com.mcxx.modules.miniSalvation.family.param.SalvationFamilyChangeParam;
import com.mcxx.modules.miniSalvation.family.param.SalvationFamilyParam;
import com.mcxx.modules.miniSalvation.family.param.SalvationObjectParam;
import com.mcxx.modules.miniSalvation.order.service.read.OrderReadService;
import com.mcxx.modules.miniSalvation.salary.service.read.FamilySalaryChangeReadService;
import com.mcxx.modules.miniSalvation.salary.service.read.MemberSalaryChangeReadService;
import com.mcxx.modules.system.entity.TaskExportEntity;
import com.mcxx.modules.system.service.write.TaskExportWriteService;
import com.mcxx.util.CommonUtil;
import com.mcxx.util.Constant;
import com.mcxx.util.DateUtil;
import com.yinhai.ta404.component.audit.vo.ExcelInfo;
import com.yinhai.ta404.core.security.vo.UserAccountVo;
import com.yinhai.ta404.core.service.BaseService;
import com.yinhai.ta404.core.transaction.annotation.TaTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
@TaTransactional
public class MiniRescueQueryExportServiceImpl extends BaseService implements MiniRescueQueryExportService {

    @Resource
    private ExportExcelService exportExcelService;
    @Autowired
    private OrderReadService orderReadService;
    @Autowired
    private FamilySalaryChangeReadService familySalaryChangeReadService;
    @Autowired
    private FileService fileService;
    @Autowired
    private TaskExportWriteService taskExportWriteService;

    @Autowired
    private MemberSalaryChangeReadService memberSalaryChangeReadService;


    @Override
    public ExcelInfo exportExcelSave(String exportType, List<String> orderIdList, SalvationObjectParam param, UserAccountVo accountVo){
        ExcelInfo excelInfo = null;
        QueryParamUtil.setBaseParamValue(param,accountVo);
        param.setBusinessType(Constant.BusinessCode.DIBAO);
        if (CommonUtil.invalidArgs(param.getSendMonth())) {
            param.setSendMonth(DateUtil.getMonthString());
        }
        if("1".equals(exportType)){



            param.setMemberIdList(orderIdList);
            List<MiniMemberExcDto> list = orderReadService.exportMiniRescueMemberList(param);
            excelInfo = exportExcelService.exportOrgOpLogs(MiniMemberExcDto.class,list,"低保救助对象信息.xls",
                    "最低生活保障救助对象列表","最低生活保障救助对象列表",false,"isHelpPoor","docHelpPoor",
                    "sex","age","nation","disabilityType","isAtSchool","education","workState",
                    "workPower","healthState","disabilityLevel","county","salaryNumber","fristStarDate","startMonth","sendMonth");
        }else if("2".equals(exportType)){

            param.setOrderIdsList(orderIdList);
            List<MiniMemberExcelDto> list = orderReadService.exportMiniRescueFamilyList(param);
            excelInfo = exportExcelService.exportOrgOpLogs(MiniMemberExcelDto.class,list,"低保救助家庭信息.xls",
                    "最低生活保障救助家庭列表","最低生活保障救助家庭列表",false,"salaryMember","reissuedSalaryNumber",
                    "phone","familyIncome","mainReason","reissuedSalaryNumber");
        }


        return excelInfo;
    }


    @Override
    public ExcelInfo exportExcelFamilySave(SalvationFamilyParam param, UserAccountVo accountVo){
        ExcelInfo excelInfo = null;
        QueryParamUtil.setBaseParamValue(param,accountVo);
        param.setBusinessType(Constant.BusinessCode.DIBAO);
        if (CommonUtil.invalidArgs(param.getSendMonth())) {
            param.setSendMonth(DateUtil.getMonthString());
        }

        List<MiniMemberExcelNewDto> list = orderReadService.exportMiniRescueList(param);
        excelInfo = exportExcelService.exportOrgOpLogs(MiniMemberExcelNewDto.class,list,"低保救助家庭信息.xls",
                    "最低生活保障救助家庭列表","最低生活保障救助家庭列表",false);



        return excelInfo;
    }


    @Override
    public ExcelInfo exportExcelChange(String exportType, List<String> orderIdList, SalvationFamilyChangeParam param, UserAccountVo accountVo){
        ExcelInfo excelInfo = null;
        QueryParamUtil.setBaseParamValue(param,accountVo);
        param.setBusinessType(Constant.BusinessCode.DIBAO);
        if("1".equals(exportType)){



            param.setMemberIdList(orderIdList);
            List<MiniMemberExcelDto> list = memberSalaryChangeReadService.exportMiniMemberChangeList(param);
            excelInfo = exportExcelService.exportOrgOpLogs(MiniMemberExcelDto.class,list,"低保对象动态信息.xls",
                    "最低生活保障对象动态列表","最低生活保障对象动态列表",false,"isHelpPoor","docHelpPoor",
                    "sex","age","nation","disabilityType","isAtSchool","education","workState",
                    "workPower","healthState","disabilityLevel","salaryMoney","changeBefore","changeAfter","helpPoorFlag","ruralObjectType","familyObjectType","fristStarDate","checkDate","startDate");
        }else if("2".equals(exportType)){

            param.setOrderIdsList(orderIdList);
            List<MiniFamilyChangeExcelDTO> list = familySalaryChangeReadService.exportMiniFamilyChangeList(param);
            excelInfo = exportExcelService.exportOrgOpLogs(MiniFamilyChangeExcelDTO.class,list,"低保家庭动态信息.xls",
                    "最低生活保障家庭动态列表","最低生活保障家庭动态列表",false,"familyNumber","savePeopleNum","poorType","startDate","salvationNo","familyObjectType","checkDate","reason");
        }


        return excelInfo;
    }
}
